//
//  CommModelSize.m
//  YiXiu
//
//  Created by yixiu on 16/8/2.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "CommModelSize.h"

#define OriginOfView(view) (view).bounds.origin
#define SizeOfView(view) (view).bounds.size
#define WidthOfView(view) (view).bounds.size.width
#define HeightOfView(view) (view).bounds.size.height


@implementation CommModelSize

//根据传入text的字体和数量计算其高
- (CGSize)sizeOfString:(NSString *)str font:(UIFont *)font{
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[NSFontAttributeName] = font;
    CGRect rect = [str boundingRectWithSize:CGSizeMake(WidthOfView([UIScreen mainScreen]) - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size;
}

- (void)setModel:(CommModel *)model{
    
    _model = model;
    
    CGSize pt_fragment_size = [self sizeOfString:model.p_content font:[UIFont systemFontOfSize:18]];
    
    self.p_content = CGRectMake(10, 70, KScreenWidth - 20, pt_fragment_size.height);

    if (model.pt_url && model.pt_url.length > 0) {
        self.imageS = [model.pt_url componentsSeparatedByString:@","];
        
        self.pt_url = CGRectMake(10, CGRectGetMaxY(self.p_content) + 10, KScreenWidth - 20, 200 * self.imageS.count);
        
    }else{
        self.pt_url = CGRectMake(10, CGRectGetMaxY(self.p_content) + 10, KScreenWidth - 20, 0.001);
    }
 
    self.totalHeight = CGRectGetMaxY(self.pt_url) + 10;
    
}



@end
